package cn.bby.query.example.model.entity.vo;

import cn.bby.query.base.ann.CacheField;
import cn.bby.query.base.ann.CacheTable;
import cn.bby.query.base.ann.CacheTableGroup;
import cn.bby.query.base.util.MetadataBuilder;
import cn.bby.query.example.model.entity.GoodsInfo;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.experimental.FieldNameConstants;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

/**
 * @author ben
 * @since 2025/4/13 02:10
 */
@Data
@CacheTableGroup(
        mainTable = @CacheTable(name = "order_info", identityFields = OrderInfoVO.Fields.id),
        subTables = {
                @CacheTable(name = "goods_info", identityFields = OrderInfoVO.Fields.goodsId),
        },
        indexFields = {
                @CacheTableGroup.Index(OrderInfoVO.Fields.orderId),
                @CacheTableGroup.Index(OrderInfoVO.Fields.goodsId),
                @CacheTableGroup.Index({OrderInfoVO.Fields.buyerName, OrderInfoVO.Fields.tenantId}),
        }
)
@FieldNameConstants
public class OrderInfoVO implements Serializable {

    private static final long serialVersionUID = -8789882420509404441L;
    /**
     * 主键
     */
    private Long id;
    /**
     * 租户ID
     */
    private String tenantId;
    /**
     * 订单ID
     */
    @CacheField(linkCol = "order_id")
    private Long orderId;
    /**
     * 买家
     */
    private String buyerName;
    /**
     * 买家手机号
     */
    private String buyerPhone;
    /**
     * 创建时间
     */
    private Long createTime;
    /**
     * 更新时间
     */
    private Long updateTime;
    /**
     * 创建人
     */
    private String createdBy;
    /**
     * 更新人
     */
    private String updatedBy;
    /**
     * 货物ID
     */
    @CacheField(linkCol = "goods_id", table = "goods_info")
    private Long goodsId;
    /**
     * 货物名称
     */
    @CacheField(linkCol = "name", table = "goods_info")
    private String goodsName;

    /**
     * 货物价格
     */
    @CacheField(linkCol = "price", table = "goods_info")
    private Double goodsPrice;

    /**
     * 货物描述
     */
    @TableField(value = "description")
    private String description;
    @CacheField(linkCol = "create_time", table = "goods_info", complex = true)
    private Timestamp createTime1;
    // 模拟多字段
    @CacheField(linkCol = "id", complex = true)
    private Boolean isTop100;
    @CacheField(linkCol = "id", complex = true)
    private boolean top1000;
    @CacheField(ignore = true)
    private GoodsInfo goodsInfo;
    @CacheField(linkCol = {"name", "seller_phone"}, complex = true)
    private List<String> tags;

    public static void main(String[] args) {
        MetadataBuilder builder = new MetadataBuilder()
                .setPackagePath("cn.bby.query.example.controller")
                .setBaseUrl("http://localhost:8080")
                .setApplicationName("query-server-example")
                .setContextPath("/api");
        System.out.println(JSON.toJSONString(builder.build()));
    }

    public void setCreateTime(Long createTime) {
        this.createTime1 = new Timestamp(createTime);
        this.createTime = createTime;
    }

}
